package api;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

//对集合类中的电影分数进行升序排序，不实现comparable接口
class Film{
    private Integer score;
    private String name;
    public Film(String name, Integer score){
        this.name = name;
        this.score = score;
    }

    public Integer getScore() {
        return score;
    }

    @Override
    public String toString() {
        return "Film{" +
                "score=" + score +
                ", name='" + name + '\'' +
                '}';
    }
}
public class CollectionSortDemo03 {
    public static void main(String[] args) {
        Film film1 = new Film("哪吒",80);
        Film film2 = new Film("葫芦娃",70);
        Film film3 = new Film("西游记",98);
        List list = new ArrayList<>();
        list.add(film1);
        list.add(film2);
        list.add(film3);
        Collections.sort(list, new Comparator<Film>() {

            @Override
            public int compare(Film o1, Film o2) {
                return o1.getScore()-o2.getScore();
            }
        });
        System.out.println(list);
    }
}
